<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	用户名： <input type="text" name="" class="userName"><br>
	密码： <input type="text" name="" class="passWord"><br>
	<button>登录</button>
	<script type="text/javascript">
		let btn = document.querySelector('button')

		btn.onclick = function(){
			//1.application/x-www-form-urlencoded
			let xhr = new XMLHttpRequest()

			xhr.open("post", "http://47.104.167.34:9100/prod-api/login")
			xhr.setRequestHeader("Content-Type", 'application/json')
			let obj = {
				username: "admin01",
				password: '123456'
			}
			xhr.send(JSON.stringify(obj))

			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					let res = JSON.parse(xhr.responseText)
					console.log(res)
					if (res.code == 200) {
						localStorage.setItem("Au", res.token)
						getInfo()
					}	
				}
			}
		}

		function getInfo() {
			let xhr = new XMLHttpRequest()

			xhr.open("get", "http://47.104.167.34:9100/prod-api/getInfo")
			xhr.setRequestHeader("Authorization", "Bearer " + localStorage.getItem("Au"))
			xhr.send(JSON.stringify())

			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					let res = JSON.parse(xhr.responseText)
					console.log(res)	
				}
			}
		}

	</script>
</body>
</html>